package com.example.diagnodroid;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TestAdapter extends BaseAdapter {

	ArrayList<Test> arrayListTests;
	Context context;


	public TestAdapter(ArrayList<Test> list, Context context) {
		super();
		arrayListTests = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		return arrayListTests.size();
	}

	@Override
	public Object getItem(int position) {
		return arrayListTests.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		EntryHolder holder = null;
		LayoutInflater mInflater = (LayoutInflater) context
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.test_entry, null);
			holder = new EntryHolder();
			holder.textName = (TextView) convertView
					.findViewById(R.id.test_name);
			holder.textDesc = (TextView) convertView
					.findViewById(R.id.test_desc);
			holder.textImage = (ImageView) convertView
					.findViewById(R.id.test_image);
			convertView.setTag(holder);
		} else {
			holder = (EntryHolder) convertView.getTag();
		}

		holder.idTest = arrayListTests.get(position).getId();
		holder.textName.setText(arrayListTests.get(position).getName());
		holder.textDesc.setText(arrayListTests.get(position).getDescription());
		holder.textImage.setImageResource(arrayListTests.get(position)
				.getImage());

		return convertView;
	}
}
